package com.qf.iot.controller;

import com.qf.iot.core.vo.R;
import com.qf.iot.entity.QfTenant;
import com.qf.iot.service.QfTenantService;
import com.qf.iot.utils.GetJwtToken;
import com.qf.iot.utils.JwtUtils;
import com.qf.iot.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.web.bind.annotation.*;

/**
 * 作者：肖骏麟
 * 时间:2023/10/27 11:37
 * 描述：优化小子
 */
@RestController
@RequestMapping("user")
@CrossOrigin
@ConditionalOnClass()
public class QfTenantLoginController {
    @Autowired(required = false)
    private QfTenantService qfTenantService;
    @PostMapping("login")
    public R login(@RequestBody QfTenant qfTenant){
        return qfTenantService.login(qfTenant);
    }
    @PostMapping("verifyToken")
    public Result verifyToken(@RequestHeader("token") String token){

        try {
            JwtUtils.paseToken(token);

            return new Result(0,"valid token");
        } catch (Exception exception) {
            exception.printStackTrace();

            return new Result(1,"invalid token");
        }


    }

    @RequestMapping("verify")
    public R verify(@RequestHeader String token){

        try {
            GetJwtToken.verify(token);
            return  R.ok("valid token");
        }catch (Exception e){
            e.printStackTrace();
            return  R.fail("invalid token");
        }

    }

}
